//
//  RNTestVC.m
//  ZCJZ
//
//  Created by sujeking on 2020/2/18.
//  Copyright © 2020 jeking. All rights reserved.
//

#import "SYHomeVC.h"
#import <MJExtension.h>

@interface SYHomeVC ()

@end

@implementation SYHomeVC

- (void)viewDidLoad {
  [super viewDidLoad];
  [self setupUI];
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
}

- (void)setupUI {
  self.navigationController.navigationBarHidden = YES;
  @try {
    RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:@{}];
    RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                     moduleName:@"Home"
                                              initialProperties:nil];
    self.view = rootView;
  } @catch (NSException *exception) {
    [self.view makeToast:exception.description duration:2.0 position:CSToastPositionCenter];
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
  } @finally {
    [self.view makeToast:@"rn 服务器没有开启" duration:2.0 position:CSToastPositionCenter];
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
    NSLog(@"rn 服务器没有开启");
  }
}

@end

//*************************************************
//
//*************************************************

@interface SYHomeVCViewModel:NSObject<RCTBridgeModule>
@end
@interface SYHomeVCViewModel()
@end
@implementation SYHomeVCViewModel
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(hiddenTabbar) {
  dispatch_async(dispatch_get_main_queue(), ^{
    [generalToolBox getcurrentVC].tabBarController.tabBar.hidden = YES;
  });
}

RCT_EXPORT_METHOD(showTabbar) {
  dispatch_async(dispatch_get_main_queue(), ^{
    [generalToolBox getcurrentVC].tabBarController.tabBar.hidden = NO;
  });
}

RCT_EXPORT_METHOD(hiddenNavbar) {
  dispatch_async(dispatch_get_main_queue(), ^{
    [generalToolBox getcurrentVC].navigationController.navigationBarHidden = YES;
  });
}

RCT_EXPORT_METHOD(showNavbar) {
  dispatch_async(dispatch_get_main_queue(), ^{
    [generalToolBox getcurrentVC].navigationController.navigationBarHidden = NO;
  });
}

RCT_EXPORT_METHOD(updateUserInfo:(NSDictionary *)data) {
  dispatch_async(dispatch_get_main_queue(), ^{
    ZCBaseUserManager *manager = [ZCBaseUserManager shareInstance];
    ZCBaseUserModel *userModel = [ZCBaseUserModel mj_objectWithKeyValues:data];
    manager.userModel = userModel;
  });
}

RCT_EXPORT_METHOD(checkOrder:(NSString *)ids num:(NSString *)num) {
  dispatch_async(dispatch_get_main_queue(), ^{
    NSDictionary *dict = @{
        @"first_cat_id":@"",
        @"referrer_uid":@"",
        @"free_id":@"",
        @"goods_id":ids,
        @"cart_ids":@"",
        @"nums":num,
        @"sku_id":ids,
        @"join_store":@"",
        @"pageNum":@"20",
        @"coupon_id":@"",
        @"page":@"2",
        @"type":@"1",
    };
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      [SSAppRouter pushViewControllerWithRoute:@"ZCOrderCheckVC" type:AppRouterManagerType_Native params:@{@"dict":dict}];
    });
  });
}

RCT_EXPORT_METHOD(pushvc:(NSString *)vcname data:(NSDictionary *)dict) {
  dispatch_async(dispatch_get_main_queue(), ^{
    [SSAppRouter pushViewControllerWithRoute:vcname type:AppRouterManagerType_Native params:dict];
  });
}


@end
